/*
 * Copyright 2011-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0.
 * See `LICENSE` in the project root for license information.
 */

package me.ijleex.jmh.benchmark;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

/**
 * RandomBenchmark.
 *
 * @author liym
 * @since 2021-04-20 22:24 新建
 */
public class RandomBenchmark {

    public RandomBenchmark() {
    }

    @Benchmark
    public String uuid() {
        return UUID.randomUUID().toString();
    }

    @Benchmark
    public String randomLong() {
        long id = ThreadLocalRandom.current().nextLong();
        return Long.toString(id);
    }

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(RandomBenchmark.class.getName())
                //.include(RandomBenchmark.class.getName() + ".*uuid*")
                .threads(10)
                // 预热N次
                .warmupIterations(5)
                // 迭代5次，每次5秒
                .measurementIterations(5).measurementTime(TimeValue.seconds(5L))
                .mode(Mode.Throughput)
                .forks(1)
                .build();

        new Runner(options).run();
    }

}
